import {
  request
} from "@/utils/request";
// let userinfo = JSON.parse(sessionStorage.getItem('userInfo'))
// let userId = ''
// let getCurrentOrganizationId() = null;
// if (userinfo) {
//   getCurrentOrganizationId() = userinfo.tenantId
//   userId = userinfo.loginName
// }
import {
  getCurrentOrganizationId,
  getCurrentUserId
} from '@/utils/util.js'
const api = {
  homepageApply:
    "/project/Windchill/servlet/rest/hzero/pmgt/project/getProjectActionsPermission",
  projectNodeList: "/deliver/Windchill/servlet/rest/hzero/pmgt/plan/getKeyActivities",
  detailMessage:
    "/project/Windchill/servlet/rest/hzero/pdm/attribute/getAttributeGroup",
  summaryData: "/project/Windchill/servlet/rest/hzero/pmgt/project/summarizeProject",
  conclusion: "/project/Windchill/servlet/rest/hzero/pmgt/project/projectEndCheck",
  getRelationProduct:
    "/project/Windchill/servlet/rest/hzero/pmgt/project/getRelatedProducts",
  getProjectAchieve:
    "/project/Windchill/servlet/rest/hzero/pmgt/project/getProjectCompletePercent",
  getQuestion: "/project/Windchill/servlet/rest/hzero/pmgt/project/getIssueCount",
  getRisk: "/project/Windchill/servlet/rest/hzero/pmgt/project/getRiskCount",
  seeRelationProject:
    "/project/Windchill/servlet/rest/hzero/pmgt/project/selectPartsForProject",
  addRelationProject:
    "/project/Windchill/servlet/rest/hzero/pmgt/project/setRelatedProducts",
  removeRelationProject:
    "/project/Windchill/servlet/rest/hzero/pmgt/project/removePartsFormProject",
  getTemplateStatus:
    "/project/Windchill/servlet/rest/hzero/pdm/core/getLifeCycleTemplate",
  updateProgress: 
    "/project/Windchill/servlet/rest/hzero/pmgt/project/progressProject",
  setTemplateStatus: 
    "/project/Windchill/servlet/rest/hzero/pdm/core/setLifeCycleState",
  getCreateProject: 
    "/project/Windchill/servlet/rest/hzero/pdm/attribute/getCreateAttributeGroup",
  getProjectGroupReference: "/project/Windchill/servlet/rest/hzero/pmgt/project/getPIProjectsUserGroup",
  getRelatedPlanning: "/project/Windchill/servlet/rest/hzero/pmgt/project/getCanReletedPlanBook",
  getRelatedProject: "/project/Windchill/servlet/rest/hzero/pmgt/project/getCanReletedPlanProject",
  getProjectAuthority: "/project/Windchill/servlet/rest/hzero/pmgt/project/hasPidimPermission",
  sendThingworxData: "/project/Windchill/servlet/rest/hzero/pmgt/project/sentProjectToThingWorx",
  getProjectType: "/project/Windchill/servlet/rest/hzero/pdm/attribute/getSubTypes",
  getImportantGrade: "/project/Windchill/servlet/rest/hzero/pmgt/project/getProjectLinkage",
  saveProject: "/project/Windchill/servlet/rest/hzero/pmgt/project/saveProject",
  editProject: "/project/Windchill/servlet/rest/hzero/pdm/attribute/getEditAttributeGroup",
  getProductCategoryByGroup: "/project/Windchill/servlet/rest/hzero/pmgt/project/getProductCategoryByGroup"
};
// 判断项目首页应用权限
export function postHomePageApply(parameter) {
  return request({
    url: api.homepageApply,
    method: "post",
    data: parameter,
    
  });
}
// 获取项目关键节点清单
export function getProjectNodeList(parameter) {
  return request({
    url: api.projectNodeList,
    method: "post",
    data: parameter,
  });
}
// 获取详细信息
export function getDetailMessage(parameter) {
  return request({
    url: api.detailMessage,
    method: "post",
    data: parameter,
  });
}
// 汇总数据
export function getSummaryData(parameter) {
  return request({
    url: api.summaryData,
    method: "post",
    data: parameter,
  });
}
// 结项检查
export function getConclusion(parameter) {
  return request({
    url: api.conclusion,
    method: "post",
    data: parameter,
  });
}
// 获取关联产品
export function getRelationProduct(parameter) {
  return request({
    url: api.getRelationProduct,
    method: "post",
    data: parameter,
  });
}
// 获取项目完成率
export function getProjectAchieve(parameter) {
  return request({
    url: api.getProjectAchieve,
    method: "post",
    data: parameter,
  });
}
// 获取问题数
export function getQuestion(parameter) {
  return request({
    url: api.getQuestion,
    method: "post",
    data: parameter,
  });
}
// 获取问题数
export function getRisk(parameter) {
  return request({
    url: api.getRisk,
    method: "post",
    data: parameter,
  });
}
// 查询关联产品
export function findRelationProject(parameter) {
  return request({
    url: api.seeRelationProject,
    method: "post",
    data: parameter,
  });
}
// 添加关联产品
export function addRelationProject(parameter) {
  return request({
    url: api.addRelationProject,
    method: "post",
    data: parameter,
  });
}
// 移除关联产品
export function removeRelationProject(parameter) {
  return request({
    url: api.removeRelationProject,
    method: "post",
    data: parameter,
  });
}
// 获取对象的生命模板周期状态
export function getTemplateStatus(parameter) {
  return request({
    url: api.getTemplateStatus,
    method: "post",
    data: parameter,
  });
}
// 更新项目进展
export function updateProgress(parameter) {
  return request({
    url: api.updateProgress,
    method: "post",
    data: parameter,
  });
}
// 设置对象的生命模板周期状态
export function setTemplateStatus(parameter) {
  return request({
    url: api.setTemplateStatus,
    method: "post",
    data: parameter,
  });
}
// 获取创建项目布局
export function getCreateProject(parameter) {
  return request({
    url: api.getCreateProject,
    method: "post",
    data: parameter,
  });
}
// 获取用户组
export function getProjectGroupReference(parameter) {
  return request({
    url: api.getProjectGroupReference,
    method: "post",
    data: parameter,
  });
}
// 获取我的应用
export function getMyApply(parameter) {
  return request({
    url: `indv/v1/${getCurrentOrganizationId()}/user-apps?userId=${getCurrentUserId()}`,
    method: 'get',
  })
}
//项目关闭流程审核人
export function getPageSelectPrincipal(parameter) {
  return request({
    url: `/workflow/Windchill/servlet/rest/hzero/foundation/workflow/getPageSelectPrincipal`,
    method: 'post',
    data: parameter,
  })
}
//得到项目关闭详细信息
export function getPanleForProject(parameter) {
  return request({
    url: `/project/Windchill/servlet/rest/hzero/pdm/attribute/getPanleForProject`,
    method: 'post',
    data: parameter,
  })
}
//得到项目关闭详细信息
export function closeProject(parameter) {
  return request({
    url: `/project/Windchill/servlet/rest/hzero/pmgt/project/closeProject`,
    method: 'post',
    data: parameter,
  })
}
// 设置我的应用
export function setMyApply(parameter) {
  return request({
    url: `indv/v1/${getCurrentOrganizationId()}/user-apps`,
    method: 'put',
    data: parameter
  })
}
// 获取关联规划书
export function getRelatedPlanning(parameter) {
  return request({
    url: api.getRelatedPlanning,
    method: 'post',
    data: parameter
  })
}
// 获取关联规划项目
export function getRelatedProject(parameter) {
  return request({
    url: api.getRelatedProject,
    method: 'post',
    data: parameter
  })
}
// 获取项目权限
export function getProjectAuthority(parameter) {
  return request({
    url: api.getProjectAuthority,
    method: 'post',
    data: parameter
  })
}
// 推送thingworx数据
export function sendThingworxData(parameter) {
  return request({
    url: api.sendThingworxData,
    method: 'post',
    data: parameter
  })
}
// 获取近期使用人员
export function getManagerMiddle(parameter) {
  return request({
    url: `indv/v1/${getCurrentOrganizationId()}/user-staffs?userId=${getCurrentUserId()}`,
    method: 'get',
  })
}
// 搜索用户
export function searchManagerMiddle(parameter) {
  return request({
    url: `indv/v1/${getCurrentOrganizationId()}/ex-mdm-users`,
    method: 'get',
    params: parameter,
  })
}
// 根据userId搜索用户
export function searchUserIdMiddle(parameter) {
  return request({
    url: `usercenter/v1/users/search`,
    method: 'post',
    data: parameter,
  })
  // return request({
  //   url: `indv/v1/${getCurrentOrganizationId()}/ex-mdm-users/search`,
  //   method: 'post',
  //   data: parameter,
  // })
}
// // 根据userIds搜索用户
// export function searchUserIdMiddle(parameter) {
//   return request({
//     url: `usercenter/v1/users/userListByAccountsPost`,
//     method: 'post',
//     data: parameter,
//   })
// }
// 域账号搜索人员
export function searchAccountMiddle(parameter) {
  return request({
    url: `usercenter/v1/users/userByAccount?account=${getCurrentUserId()}`,
    method: 'get',
    data: parameter,
  })
}
// 编辑保存使用人员
export function serveManager(parameter) {
  return request({
    url: `indv/v1/${getCurrentOrganizationId()}/user-staffs`,
    method: 'put',
    data: parameter,
  })
}
// 获取项目类型
export function getProjectType(parameter) {
  return request({
    url: api.getProjectType,
    method: 'post',
    data: parameter
  })
}
// 根据项目小类获取重要等级
export function getImportantGrade(parameter) {
  return request({
    url: api.getImportantGrade,
    method: 'post',
    data: parameter
  })
}
// 保存项目
export function saveProject(parameter) {
  return request({
    url: api.saveProject,
    method: 'post',
    data: parameter
  })
}
// 编辑项目
export function editProject(parameter) {
  return request({
    url: api.editProject,
    method: 'post',
    data: parameter
  })
}
export function getProductCategoryByGroup(parameter) {
  return request({
    url: api.getProductCategoryByGroup,
    method: 'post',
    data: parameter
  })
}